<?php

require_once ('Zend/Validate/Interface.php');
require_once ('Zend/View/Helper/FormPassword.php');



class Api_Form_Collaboration extends Zend_Form {
	public function __construct() {
		parent::__construct ();
		
		$this->setAttrib ( 'class', 'registrationForm' );
		
		// Create and configure username element:
//		$email = $this->createElement ( 'text', 'email', array ('maxlength' => '40' ) )->setLabel ( 'wda' )->addValidator ( 'EmailAddress', false, array ('messages' => $this->getEmailMessages () ) )->addValidator ( 'stringLength', false, array (6, 40, 'messages' => $this->getCustomMessages () ) )->setRequired ( true );
//		$email->getDecorator ( 'Label' )->setOption ( 'escape', false );
		
		// Captcha element initialization
		$captcha = $this->createElement ( 
			'captcha', 'humanizm', array (
				'captcha' => 'Image', 
				'onkeyup' => 'maybeDisableButton()', 
				'captchaOptions' => array (
					'captcha' => 'Image', 
					'wordLen' => 4, 
					'timeout' => 60, 
					'width' => 150, 
					'tag' => 'td',
					'font' => 'fonts/timesi.ttf' 
				) 
			) 
		)->setLabel ( 'Захист </br> проти роботів:' );
		
		$captcha->setDecorators ( 
			array (
				'Description', 'Errors', 
				array (
					'decorator' => array ('td' => 'HtmlTag' ), 
					'options' => array ('tag' => 'td' ) 
				), 
				array (
					'Label', array ('tag' => 'td' ) 
				), 
				array (
					'decorator' => array ('td' => 'HtmlTag' ), 
					'options' => array ('tag' => 'td' ) 
				) 
			) 
		);
		$captcha->getDecorator ( 'Label' )->setOption ( 'escape', false );
		
		// Submit button initialization initialization
		

//		$receivemail = $this->createElement ( 'hidden', 'subscribe_news', array ('value' => true ) );
//		$receivemail->setDecorators ( array ('ViewHelper', 'Label', array (array ('data' => 'HtmlTag' ), array ('tag' => 'td', 'colspan' => '2' ) ), array (array ('row' => 'HtmlTag' ), array ('tag' => 'tr' ) ) ) );
//		$receivemail->getDecorator ( 'Label' )->setOption ( 'escape', false );
		
		// Add elements to form:
		$this->addElements ( array ($captcha ) );
	
	}
	
	public function isValid($data) {
		$retval = parent::isValid ( $data );
		return $retval;
	}
	
	protected function getCustomMessages() {
		// TODO: Cache error values
		$messages = array ();
		$messages [Zend_Validate_StringLength::TOO_SHORT] = 'Too short string';
		$messages [Zend_Validate_StringLength::TOO_LONG] = 'Too long string';
		return $messages;
	}
	
	protected function getEmailMessages() {
		$messages = array ();
		$messages [Zend_Validate_EmailAddress::INVALID_FORMAT] = 'emailAddressInvalid';
		$messages [Zend_Validate_Hostname::INVALID_HOSTNAME] = 'hostnameInvalidHostname';
		$messages [Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED] = 'hostnameLocalNameNotAllowed';
		$messages [Zend_Validate_Hostname::UNKNOWN_TLD] = 'hostnameUnknownTld';
		$messages [Zend_Validate_Hostname::UNDECIPHERABLE_TLD] = 'hostnameUndecipherableTld';
		$messages [Zend_Validate_Hostname::INVALID_LOCAL_NAME] = 'hostnameInvalidLocalName';
		
		return $messages;
	}
}